public with sharing class PageQueryUtil {
    
    private ApexPages.StandardSetController ssc;
    
    public PageQueryUtil(String sql) {
        this.ssc = new ApexPages.StandardSetController(Database.getQueryLocator(sql));
    }
    
    /**
     *@Function: 首页
     *
     */
    public Map<String, Object> first() {
        this.ssc.first();
        return this.getData();
    }
    
    /**
     *@Function: 尾页
     *
     */
    public Map<String, Object> last() {
        this.ssc.last();
        return this.getData();
    }
    
    /**
     *@Function: 下一页
     *
     */
    public Map<String, Object> next() {
        this.ssc.next();
        return this.getData();
    }
    
    /**
     *@Function: 上一页
     *
     */
    public Map<String, Object> previous() {
        this.ssc.previous();
        return this.getData();
    }
    
    /**
     *@Function: 根据当前页数获取数据
     *
     */
    private Map<String, Object> getData() {
        List<Object> data = this.ssc.getRecords();
        Map<String, Object> result = new Map<String, Object>();
        result.put('currentPage', this.ssc.getPageNumber());
        result.put('pageSize', this.ssc.getPageSize());
        result.put('actualSize', data.size());
        result.put('data', data);
        result.put('hasNext', this.ssc.getHasNext());
        result.put('hasPrevious', this.ssc.getHasPrevious());
        
        return result;
    }
    
    /**
     *@Function: 设置当前页数
     *
     */
    public void setPageNumber(Integer pageNumber) {
        this.ssc.setPageNumber(pageNumber);
    }
    
    /**
     *@Function: 设置当前每页数据量
     *
     */
    public void setPageSize(Integer pageSize) {
        this.ssc.setPageSize(pageSize);
    }
    
    /**
     *@Function: 获取指定页数的数据
     *
     */
    public Map<String, Object> goto(Integer pageNumber) {
        this.setPageNumber(pageNumber);
        return this.getData();
    }
}